package cn.swh.guguanjia.service.impl;

import cn.swh.guguanjia.entity.SysResource;
import cn.swh.guguanjia.mapper.SysResourceMapper;
import cn.swh.guguanjia.service.SysResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SysResourceServicelmpl extends BaseServicelmpl<SysResource, Long> implements SysResourceService {

    @Autowired
    SysResourceMapper SysResourceMapper;

    @Override
    public PageInfo<SysResource> selectPage(int pageNum, int pageSize, Map<String, Object> map) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysResource> sysResources = SysResourceMapper.selectPage(map);
        PageInfo<SysResource> pageInfo = new PageInfo<>(sysResources);
        return pageInfo;
    }

    @Override
    public List<SysResource> selectById(long rid) {
        return SysResourceMapper.selectById(rid);
    }

    public List<SysResource> selectByUid(long uid) {
        return SysResourceMapper.selectByUid(uid);
    }

    @Override
    @Cacheable(cacheNames = "resourceCache", key = "'cn.swh.guguanjia.service.impl.SysResourceServicelmpl:selectResources'")
    public List<SysResource> selectResources() {
        return SysResourceMapper.selectResources();
    }
}
